package com.zj.juc.study.atomic;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName AtomicReferrenceDemo
 * @Description 原子引用
 * @createTime 2025年01月02日 22:19
 */
public class AtomicReferenceDemo {

    public static void main(String[] args) {
        AtomicReference<User> userAtomicReference = new AtomicReference<>();
        User z3 = new User("zs",24);
        userAtomicReference.set(z3);
        User l4 = new User("l4",25);
        System.out.println(userAtomicReference.compareAndSet(z3, l4));
    }
}

@AllArgsConstructor
@Data
class User{
    String userName;

    Integer age;
}
